package com.txf.simple.ui.widget;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * @author txf
 * @Title
 * @package com.txf.simple.ui.widget
 * @date 2017/2/10 0010
 */
public class ADWidget extends RelativeLayout {
    private ViewPager mViewPager;
    private List<String> mDatas;

    public ADWidget(Context context) {
        super(context);
        init();
    }

    public ADWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ADWidget(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    /**
     * 初始化
     */
    private void init() {
        mViewPager = new ViewPager(getContext());
        addView(mViewPager, buildLayoutParams());
    }

    private RelativeLayout.LayoutParams buildLayoutParams() {
        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }

    public void setData(List<String> data) {
        if (data.size() > 0)
            mDatas = data;
        else
            mDatas = new ArrayList<>();
        mViewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return mDatas.size();
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {

                return super.instantiateItem(container, position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {

            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
        });


    }


}
